package com.pearadmin.modules.sys.controller.work;


import com.github.pagehelper.PageInfo;
import com.pearadmin.common.tools.string.Convert;
import com.pearadmin.common.web.base.BaseController;
import com.pearadmin.common.web.domain.request.PageDomain;
import com.pearadmin.common.web.domain.response.Result;
import com.pearadmin.common.web.domain.response.module.ResultTable;
import com.pearadmin.modules.sys.domain.WorkOperateDetail;
import com.pearadmin.modules.sys.service.IWorkOperateDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * 运行工作详情Controller
 *
 * @author Mr.Ling
 * @date 2021-12-14
 */
@RestController
@RequestMapping("/work/operateDetail")
public class WorkOperateDetailController extends BaseController {

    private String prefix = "work/operateDetail";

    @Autowired
    private IWorkOperateDetailService workOperateDetailService;

    @GetMapping("/main")
    @PreAuthorize("hasPermission('/work/operateDetail/main','work:operateDetail:main')")
    public ModelAndView main() {
        return jumpPage(prefix + "/main");
    }

    /**
     * 查询运行工作详情列表
     */
    @ResponseBody
    @GetMapping("/data")
    @PreAuthorize("hasPermission('/work/operateDetail/data','work:operateDetail:data')")
    public ResultTable list(@ModelAttribute WorkOperateDetail workOperateDetail, PageDomain pageDomain) {
        PageInfo<WorkOperateDetail> pageInfo = workOperateDetailService.selectWorkOperateDetailPage(workOperateDetail, pageDomain);
        return pageTable(pageInfo.getList(), pageInfo.getTotal());
    }

    /**
     * 新增运行工作详情
     */
    @GetMapping("/add")
    @PreAuthorize("hasPermission('/work/operateDetail/add','work:operateDetail:add')")
    public ModelAndView add() {
        return jumpPage(prefix + "/add");
    }

    /**
     * 新增保存运行工作详情
     */
    @ResponseBody
    @PostMapping("/save")
    @PreAuthorize("hasPermission('/work/operateDetail/add','work:operateDetail:add')")
    public Result save(@RequestBody WorkOperateDetail workOperateDetail) {
        return decide(workOperateDetailService.insertWorkOperateDetail(workOperateDetail));
    }

    /**
     * 修改运行工作详情
     */
    @GetMapping("/edit")
    @PreAuthorize("hasPermission('/work/operateDetail/edit','work:operateDetail:edit')")
    public ModelAndView edit(String id, ModelMap mmap) {
        WorkOperateDetail workOperateDetail = workOperateDetailService.selectWorkOperateDetailById(id);
        mmap.put("workOperateDetail", workOperateDetail);
        return jumpPage(prefix + "/edit");
    }

    /**
     * 修改保存运行工作详情
     */
    @ResponseBody
    @PutMapping("/update")
    @PreAuthorize("hasPermission('/work/operateDetail/edit','work:operateDetail:edit')")
    public Result update(@RequestBody WorkOperateDetail workOperateDetail) {
        return decide(workOperateDetailService.updateWorkOperateDetail(workOperateDetail));
    }

    /**
     * 删除运行工作详情
     */
    @ResponseBody
    @DeleteMapping("/batchRemove")
    @PreAuthorize("hasPermission('/work/operateDetail/remove','work:operateDetail:remove')")
    public Result batchRemove(String ids) {
        return decide(workOperateDetailService.deleteWorkOperateDetailByIds(Convert.toStrArray(ids)));
    }

    /**
     * 删除
     */
    @ResponseBody
    @DeleteMapping("/remove/{id}")
    @PreAuthorize("hasPermission('/work/operateDetail/remove','work:operateDetail:remove')")
    public Result remove(@PathVariable("id") String id) {
        return decide(workOperateDetailService.deleteWorkOperateDetailById(id));
    }
}
